home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbasicpg.zip / CALL_EX.BAS < prev    next >
BASIC Source File  |  1988-09-17  |  2KB  |  69 lines

  1. ' *** CALL_EX.BAS
  2. '
  3. DEFINT A-Z
  4. CONST MAXFILES = 5, ARRAYDIM = MAXFILES + 1
  5. DIM File$(1 TO ARRAYDIM)
  6. ' Separate command line into arguments.
  7. CALL Comline (Numargs,File$(),ARRAYDIM)
  8. IF Numargs < 3 OR Numargs >MAXFILES THEN
  9.   ' Too many or too few files.
  10.    PRINT "Use more than 3 and fewer than";MAXFILES;"files"
  11. ELSE
  12.   ' Printout list of files.
  13.    CALL Printout(File$(),Numargs)
  14. END IF
  15. END
  16.  
  17. SUB Comline(NumArgs,Args$(1),MaxArgs) STATIC
  18. ' Subroutine to get command line and split into arguments.
  19. ' Parameters:  NumArgs : Number of args found.
  20. '              Args$() : Array in which to return arguments.
  21. '              MaxArgs : Maximum number of arguments
  22. CONST TRUE = -1, FALSE = 0
  23. NumArgs=0 : In=FALSE
  24. ' Get the command line using the COMMAND$ function.
  25.    Cl$ = COMMAND$
  26.    L = LEN(Cl$)
  27. ' Go through the command line a character at a time.
  28.    FOR I = 1 TO L
  29.       C$ = MID$(Cl$,I,1)
  30.       'Test for a blank or tab.
  31.       IF (C$ <> " " AND C$ <> CHR$(9)) THEN
  32.          ' Neither blank nor tab.
  33.          ' Test already inside an argument.
  34.          IF NOT In THEN
  35.          ' You've found the start of a new argument.
  36.          ' Test for too many arguments.
  37.             IF NumArgs=MaxArgs THEN EXIT FOR
  38.             NumArgs=NumArgs+1
  39.             In=TRUE
  40.          END IF
  41.          ' Add the character to the current argument.
  42.          Args$(NumArgs)=Args$(NumArgs)+C$
  43.       ELSE
  44.          ' Found a blank or a tab.
  45.          ' Set "Not in an argument" flag to FALSE.
  46.          In=FALSE
  47.       END IF
  48.    NEXT I
  49. END SUB
  50.  
  51. SUB Printout(F$(1),N) STATIC
  52.    ' Open target file.
  53.    OPEN F$(N) FOR OUTPUT AS #3
  54.    ' Loop executes once for each file.
  55.    ' Copy the first N-1 files onto the Nth file.
  56.    FOR File = 1 TO N - 1
  57.       OPEN F$(File) FOR INPUT AS #1
  58.       DO WHILE NOT EOF(1)
  59.          'Read file.
  60.      LINE INPUT #1, Temp$
  61.          'Write data to target file.
  62.      PRINT #3, Temp$
  63.      PRINT Temp$
  64.       LOOP
  65.       CLOSE #1
  66.     NEXT
  67.     CLOSE
  68. END SUB
  69.